/*
 * TMC6200.h
 *
 *  Created on: 14.03.2018
 *      Author: ed
 */

#ifndef TMC_IC_TMC6200_H_
#define TMC_IC_TMC6200_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "API_Header.h"
#include "TMC6200_Register.h"
#include "TMC6200_Constants.h"
#include "drv8301.h"


typedef enum 
{
  TMC6200_ShuntAmpGain_5VpV =  0,   //!<  5 V per V
  TMC6200_ShuntAmpGain_10VpV = 1,   //!< 10 V per V
  TMC6200_ShuntAmpGain_20VpV = 3    //!< 20 V per V
} TMC6200_ShuntAmpGain_e;

//TMC6200 gloabl config
typedef struct{
  bool driverDisable;         //1 失能驱动
  bool intfaceMode;           //0 独立信号控制H+L 1 
  bool faultDirect;           //0 当且仅当某一路电桥由于过流、过温而关闭时触发保护 1任何导致过流的情况
  uint8_t amplification;      //放大倍数 0->5VpV 1->10VpV 2->10VpV  3->20VpV
  bool amplifierSwitch;       //0开启 1关闭（降低功耗）
  bool testMode;              //0通常模式 此接口不是为user使用。
}TMC6200_GCONF_Reg;

//TMC6200 Short config
typedef struct{
  uint8_t S2VS_LEVEL;
  uint8_t S2G_LEVEL;
  uint8_t SHORTFILTER;
  bool shortdelay;
  uint8_t RETRY;
  bool protect_parallel;
  bool disable_S2G;
  bool disable_S2VS;
}TMC6200_SHORT_CONF_Reg;

//TMC6200 DRV_CONF 
typedef struct{
  uint8_t BBMCLKS;        //BBM分频
  uint8_t OTSELECT;       //过温分级选择 00：最高150
  uint8_t DRVSTRENGTN;    //驱动能力选择
}TMC6200_DRV_Reg;


typedef struct _DRV8301_Obj_ TMC6200_Obj;
typedef TMC6200_Obj *TMC6200_Handle;

int tmc6200_readInt(TMC6200_Handle handle, uint8_t address);
void tmc6200_writeInt(TMC6200_Handle handle, uint8_t address, int value);
void tmc6200_enable(TMC6200_Handle handle);
void tmc6200_setGCONF(TMC6200_Handle handle,TMC6200_GCONF_Reg reg);
void tmc6200_setDRVReg(TMC6200_Handle handle,TMC6200_DRV_Reg reg);
 #ifdef __cplusplus
}
#endif
#endif /* TMC_IC_TMC6630_H_ */
